package cn.bankAutoOffice.config;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.InputStream;
import java.util.zip.ZipInputStream;

/**
 * @author 金健伟
 * @DATE 2023/4/13 16:48
 * 功能说明：
 */

@Configuration
public class ActivityConfig {

    /* 单个文件部署方式 */
    @Bean
    public ProcessEngineConfiguration processEngineConfiguration() {
        ProcessEngineConfiguration engineConfiguration =
                ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activity-spring.cfg.xml");
        ProcessEngine processEngine = engineConfiguration.buildProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();

        // repositoryService.createDeployment().addClasspathResource("activity/QingJia.bpmn20.xml")
        //         .name("QingJia").deploy();

        repositoryService.createDeployment().addClasspathResource("activity/Customer_Complaint.bpmn20.xml")
                .name("TouSu").deploy();

        return engineConfiguration;
    }

    /* 压缩包部署方式 */
    // public void deployProcessByZip() {
    //     ProcessEngineConfiguration engineConfiguration =
    //             ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activity-spring.cfg.xml");
    //     // 定义zip输入流
    //     InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("bpmn/evection.zip");
    //     ZipInputStream zipInputStream = new ZipInputStream(inputStream);
    //     ProcessEngine processEngine = engineConfiguration.buildProcessEngine();
    //     // 获取repositoryService
    //     RepositoryService repositoryService = processEngine.getRepositoryService();
    //     // 流程部署
    //     Deployment deployment = repositoryService.createDeployment()
    //             .addZipInputStream(zipInputStream)
    //             .deploy();
    //     System.out.println("流程部署id：" + deployment.getId());
    //     System.out.println("流程部署名称：" + deployment.getName());
    // }


}
